<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;

class AIndexController extends Controller{
    public function getAllUser(Request $request){
        $alluser = DB::table('waihui_member')
                   ->select('username','tel')
                   ->get();    
                
        dd($alluser);        
    }
    //持仓订单
    public function holdOrderList(){
        $result = DB::table('waihui_order as o')->join('waihui_member as m','o.tel','m.tel')->select('m.id','m.username','o.begin_point','o.begin_time','o.tradeid','o.buy_status','o.typename','o.profit_point','o.loss_point')->where(array('o.ispersonal'=>0,'o.isstop'=>1))->orderBy('m.id','asc')->orderBy('o.begin_time','asc')->get()->toArray();
        dd($result);
    }
    //总赢排行
    public function profitPointList(){
        $result = DB::table('waihui_order as o')->join('waihui_member as m','o.tel','m.tel')->select('m.id','m.username','m.grade', DB::raw('count(o.tel) as ordernum'),DB::raw('ROUND(SUM(final_point),2) profitpoint'), DB::raw("ROUND((SUM(final_point)/count(o.tel)),2) AS single_final_point"),DB::raw("ROUND(((count(case when o.trade_status='1' then 1 end) / count(o.tel))*100),2) AS winrate"))->where(array('o.ispersonal'=>0,'o.isstop'=>0))->orderBy('profitPoint','desc')->groupBy('m.tel')->get()->toArray();
        dd($result);
    }
    //近一周排行
    public function weekPointList(){
        $result = DB::table('waihui_order as o')->join('waihui_member as m','o.tel','m.tel')->select('m.id','m.username','m.grade', DB::raw('count(o.tel) as ordernum'),DB::raw('ROUND(SUM(final_point),2) profitpoint'), DB::raw("ROUND((SUM(final_point)/count(o.tel)),2) AS single_final_point"),DB::raw("ROUND(((count(case when o.trade_status='1' then 1 end) / count(o.tel))*100),2) AS winrate"))->where(array('o.ispersonal'=>0,'o.isstop'=>0))->whereBetween('end_time', [strtotime('-1 week'), time()])->orderBy('profitPoint','desc')->groupBy('m.tel')->get()->toArray();
        dd($result);
    }
}
